10 Velocity

10.1 Introduction to Velocity

10.1.1 What is Velicity?

  • 템플릿 언어

결국은 단계적으로 없어지고 FreeMarker으로 대체될 것이다.

Template languages

  • 개발자가 비즈니스로직과 프리젠테이션 로직을 분리하기 위한 간단한 데이터접근과 제어를 제공한다.

Runtime vs. compile-time

  • JSP는 정적이고, 컴파일타임 언어이고 Velocity는 런타임 언어이다.

Getting ready to use Velocity

  • 구성에 관련된 3가지 화일

xwork.xml


<result-type name="velocity" class="com.opensymphony.webwork.dispatcher.VelocityResult"/>

webwork.properties


### Location of velocity.properties file.
webwork.velocity.configfile = velocity.properties

### Comma separated list of VelocityContext classnames
webwork.velocity.contexts =

#JSP tag packages
webwork.velocity.tag.path = com.opensymphony.webwork.views.velocity.ui

velocity.properties

기본적으로, WebWork는 classloader과 화일 시스템, 또는 데이터베이스로부터 자원을 로딩한다.

현재 환경에서 web.xml에 추가한 부분
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>
org.apache.velocity.tools.view.servlet.VelocityViewServlet
</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>

10.2 Basic syntax and operations

  • vtl(velocity template language) 사용

10.2.1 Property access

10.2.2 Method calls

10.2.3 Control statements: if/else and logs

10.2.4 Assigning variables

10.3 Advanced techniques

10.3.1 The VelocityContext

10.3.2 WebWork-supplied objects in the context

10.3.3 Customizing the Velocity context

10.4 Using JSP tags in Velocity

  • 모든 어플리케이션 서버에서 정확하게 작동하는 것을 보장하지 않고 완벽하지 않다.

10.5 Loading Velocity templates

  • resource loaders의 개념을 지원한다.
  • wwfile java.io.File객체를 액세스한다.
  • wwclass 클래스패스로부터의 템플릿를 로딩한다.

10.6 Summary